﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wx.Api;
using Wx.Model.Message;
using Utilities.Log;
namespace TestWeb.Controllers
{
    public class ValiDateController : Controller
    {
        private LogHelper log = new LogHelper(typeof(ValiDateController));
        // GET: ValiDate
        [HttpGet]
        public ActionResult Index(string signature, string timestamp, string nonce, string echostr, string postStr)
        {
            log.info("V\r\n");

            Wx.Event.Listen l = new Wx.Event.Listen();
            l.Receive(this.HttpContext);
            Response.Write(string.Empty);
            return View();
        }

        [HttpPost]
        public ActionResult Index()
        {
            log.info("Event\r\n");
            Wx.Event.Listen l = new Wx.Event.Listen();
            l.OnRecvText += new EventHandler<Wx.Model.Event.Receive>(OnText);
            l.Receive(this.HttpContext);
            return View();
        }

        protected void OnText(object sender, Wx.Model.Event.Receive param)
        {
            if (param != null)
            {
                Wx.Model.Message.Text txt = new Wx.Model.Message.Text();
                txt.Content = "test back message";
                txt.CreateTime = ((int)DateTime.Now.Ticks).ToString();
                txt.MsgType = "text";
                txt.ToUserName = param.FromUserName;
                txt.FromUserName = param.ToUserName;
                Response.Write(txt.GetMessageString());
            }
            else
            {
                Response.Write("success");
            }
        }
    }
}